********************************************************************************
*
**#	Fig 2: Number of DV cases in Jail Docket by court specialization
*
********************************************************************************

use "${DATA}/data_DV.dta", clear
	
preserve

	*	Keep DV cases
	
	keep if dv_case == 1
	
	*	Calc no. of cases heard by DV court vs General court:
	
	gen total_num = 1
	
	collapse (sum) total_num, by(year_court dv_judge)
	
	*	Graph note: What % of cases heard by DV judges b/w 2000-2006? 
	
	by year_court: egen total_both = sum(total_num)
	
	gen perc_dv = (total_num/total_both)*100 if dv_judge == 1
	
	egen avg_dv = mean(perc_dv) 
	
	qui sum avg_dv
	
	local avg: di %2.1f r(max)
	
	*	labels for lines: 
	
	gen str15 l_label = "" 
	
	qui sum year_court
	
	replace l_label = "DV Court"		if dv_judge==1 & year_court==r(max)
	
	replace l_label = "General Court"	if dv_judge==0 & year_court==r(max)
	
	* 	twoway options: 
	
	# d ;
	local 	label_opts 
			"lcolor(black)
			lwidth(medthick) 
			msize(small) 
			mcolor(black)
			mlab(l_label) 
			msize(zero)
			mlabsize(small) 
			mlabcolor(black)"
	;

	# d ; 
	
	graph twoway 
		(connected 	total_num year_court if dv_judge==1,`label_opts') 
		(connected 	total_num year_court if dv_judge==0,`label_opts' lpattern(dash))
		(spike 		total_num year_court if dv_judge==0, lpattern(dot) lcolor(gs7) lwidth(thin))
		, 
		xtitle("Year", margin(0 0 0 2.5))
		ytitle("")
		xlabel(2000 (1) 2006, labsize(small))
		xscale(
		range(2000 2007.5))
		ylabel(0 (50) 250, angle(0) nogrid labsize(small)) 	
		note(
			"On average, `avg'% of DV cases in the jail docket are heard by DV courts.",
			size(small) margin(l-8 t+2 b-2))
		xsize(20) ysize(16)
		legend(off)	;
		
	# d cr
	
	graph save "${OUTPUT}/fig2.gph", replace	
	
restore 
